package com.yuwei.module_cash_desk.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.lib_http.entity.CashDeskEntity
import com.bw.lib_http.entity.ChargeEntity
import com.yuwei.module_cash_desk.model.CashDeskRepository
import kotlinx.coroutines.launch

class CashDeskViewModel: BaseViewModel2<CashDeskRepository>() {
    override fun createRepository(): CashDeskRepository = CashDeskRepository()
    val getCashDeskSuccess by lazy { MutableLiveData<CashDeskEntity>() }
    val getChargeListSuccess by lazy { MutableLiveData<ChargeEntity>() }
    fun getCashDesk(){
        mViewModelScope.launch(mDispatcher){
            val res = mRepository.getCashDesk()
            if (res.code == 200){
                getCashDeskSuccess.postValue(res.data)
            }else{
                mErrorLiveData.postValue(res.message)
            }
        }
    }
    fun getChargeList(){
        mViewModelScope.launch(mDispatcher){
            val res = mRepository.getChargeList()
            if (res.code == 200){
                getChargeListSuccess.postValue(res.data)
            }else{
                mErrorLiveData.postValue(res.message)
            }
        }
    }

}